package com.riko.comic.core.result;

/**
 * 异常返回结果
 *
 * @author riko
 * @since 2021/10/29
 */
public enum ResultCode {
    SUCCESS(200, "请求成功"),
    SYSTEM_ERROR(500, "系统错误"),
    UNKNOWN_REQUEST(404, "未知请求,请核对后再重试!"),
    PARAM_IS_INVALID(1000, "参数错误"),
    USER_IS_EXISTED(1001, "用户已存在"),
    USER_NOT_EXIST(1002, "用户不存在"),
    LOGIN_EXCEPTION(1003, "登陆失败,密码或账户名错误"),
    ;

    private Integer code;
    private String message;


    public static ResultCode getByCode(Integer code) {
        for (ResultCode value : values()) {
            if (value.getCode().equals(code)) {
                return value;
            }
        }
        return null;
    }

    public static ResultCode getByMessage(String message) {
        for (ResultCode value : values()) {
            if (value.getMessage().equals(message)) {
                return value;
            }
        }
        return null;
    }


    ResultCode(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public Integer getCode() {
        return this.code;
    }

    public String getMessage() {
        return this.message;
    }
}
